#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    bool lemonadeChange(vector<int>& bills)
    {
        int five = 0, ten = 0;
        for (auto e : bills)
        {
            if (e == 5) 
                ++five;
            else if (e == 10)
            {
                if (five)
                {
                    --five;
                    ++ten;
                }
                else
                    return false;
            }
            else
            {
                if (five && ten)
                {
                    --five;
                    --ten;
                }
                else if (five >= 3)
                    five -= 3;
                else
                    return false;
            }
        }
        return true;
    }
};

int main()
{
    vector<int> v = { 5,5,5,10,20 };
    cout << Solution().lemonadeChange(v) << endl;

	return 0;
}